<?php

/**
 *  @FileComment            [货品列表模型]
 *  @ProjectName             项目名称：shopFrame
 *  @FileName                   文件名称：GoodsListModel.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-13 22:27:04
 *  *
 */
class GoodsListModel extends Model {

        public $table = 'goods_list';
        public $validate = array(
            array('combattrid', '_nonull', '请选择商品规格', 2, 3),
            array('stock', 'nonull', '库存不能为空', 2, 3),
            array('number', 'nonull', '货号不能为空', 2, 3),
            array('number', '_distinct', '货品编号不能重复', 2, 3)
        );

        public function _distinct($name, $value, $msg, $arg) {
                $data = $this->where('number=' . $value)->find();
                if ($data) {
                        return $msg;
                } else {
                        return true;
                }
        }

        public $auto = array(
            array('combattrid', '_comb', 'method', 2, 3),
        );

        public function _comb($value) {
                $str = implode(',', $value);
                return $str;
        }

        public function _nonull($name, $value, $msg, $arg) {
                foreach ($value as $v) {
                        if (!$v) {
                                return $msg;
                        }
                }
                return true;
        }

        public function add_data() {
                return $this->add();
        }

        public function get_data($gid) {
                return $this->where(array('gid' => $gid))->all();
        }

        public function get_one_field_data($where) {
                return $this->where($where)->getField('stock');
        }

        public function get_one_data($glid) {
                return $this->where(array('glid' => $glid))->find();
        }

        public function del_data($glid) {
                return $this->where(array('glid' => $glid))->del();
        }

        public function get_o_data($where) {
                return $this->where($where)->find();
        }

        public function get_Field_data($where) {
                return $this->where($where)->find();
        }

        public function update_data($glid = NULL, $data = NULL) {
                return $this->where(array('glid' => $glid))->update($data);
        }

}
